<template>
  <div class="w-full p-2">
    <el-form :model="formData" label-width="180px">
      <!-- 蒸汽流量 -->
      <el-form-item label="蒸汽流量设定范围">
        <el-input-number v-model="formData.steam_flow_SV_range[0]" :min="40" :max="60" placeholder="下限" />
        <el-input-number v-model="formData.steam_flow_SV_range[1]" :min="40" :max="60" placeholder="上限" />
      </el-form-item>
      <!-- <el-form-item label="蒸汽流量当前值">
        <el-input v-model="formData.steam_flow_PV[0]" disabled />
      </el-form-item> -->

      <!-- 空气预热器温度 -->
      <!-- <el-form-item label="空气预热器出口风温">
        <el-tooltip class="box-item" effect="dark" content="出口风温" placement="top-start">
          <el-input v-model="formData.air_preheater_temperature_PV[0]" disabled placeholder="出口风温" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="一级出口风温" placement="top-start">
          <el-input v-model="formData.air_preheater_temperature_PV[1]" disabled placeholder="一级出口风温" />
        </el-tooltip>
      </el-form-item> -->

      <!-- 锅炉集汽联箱温度 -->
      <el-form-item label="锅炉集汽联箱温度设定范围">
        <el-input-number v-model="formData.steam_header_temperature_SV_range[0]" :min="0" placeholder="下限" />
        <el-input-number v-model="formData.steam_header_temperature_SV_range[1]" :min="0" placeholder="上限" />
      </el-form-item>
      <!-- <el-form-item label="锅炉集汽联箱温度当前值">
        <el-input v-model="formData.steam_header_temperature_PV[0]" disabled />
      </el-form-item> -->

      <!-- 焚烧炉温度 -->
      <el-form-item label="焚烧炉温度设定范围">
        <el-input-number v-model="formData.incinerator_temperature_SV_range[0]" :min="0" placeholder="下限" />
        <el-input-number v-model="formData.incinerator_temperature_SV_range[1]" :min="0" placeholder="上限" />
      </el-form-item>
      <!-- <el-form-item label="焚烧炉温度当前值">
        <el-tooltip class="box-item" effect="dark" content="温度上左" placement="top-start">
          <el-input v-model="formData.incinerator_temperature_PV[0]" disabled placeholder="温度上左" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="温度下右" placement="top-start">
          <el-input v-model="formData.incinerator_temperature_PV[1]" disabled placeholder="温度下右" />
        </el-tooltip>
      </el-form-item> -->

      <!-- 焚烧炉含氧量 -->
      <el-form-item label="焚烧炉含氧量设定范围">
        <el-input-number v-model="formData.incinerator_oxygen_content_SV_range[0]" :min="0" placeholder="下限" />
        <el-input-number v-model="formData.incinerator_oxygen_content_SV_range[1]" :min="0" placeholder="上限" />
      </el-form-item>
      <!-- <el-form-item label="焚烧炉含氧量当前值">
        <el-input v-model="formData.incinerator_oxygen_content_PV[0]" disabled />
      </el-form-item> -->

      <!-- 焚烧炉压力 -->
      <el-form-item label="焚烧炉压力设定范围">
        <el-input-number v-model="formData.incinerator_pressure_SV_range[0]" :min="0" placeholder="下限" />
        <el-input-number v-model="formData.incinerator_pressure_SV_range[1]" :min="0" placeholder="上限" />
      </el-form-item>
      <!-- <el-form-item label="焚烧炉压力当前值">
        <el-tooltip class="box-item" effect="dark" content="左压力值" placement="top-start">
          <el-input v-model="formData.incinerator_pressure_PV[0]" disabled placeholder="左压力值" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="右压力值" placement="top-start">
          <el-input v-model="formData.incinerator_pressure_PV[1]" disabled placeholder="右压力值" />
        </el-tooltip>
      </el-form-item> -->

      <!-- 炉排风压 -->
      <!-- <el-form-item label="逆推炉排风压">
        <el-tooltip class="box-item" effect="dark" content="1#1#风室压力" placement="top-start">
          <el-input
            label="1#1#风室压力"
            v-model="formData.backward_grate_wind_pressure_PV[0]"
            disabled
            placeholder="1#1#风室压力"
          />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="1#2#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[0]" disabled placeholder="1#2#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="1#3#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[0]" disabled placeholder="1#3#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="1#4#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[0]" disabled placeholder="1#4#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="2#1#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[1]" disabled placeholder="2#1#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="2#2#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[1]" disabled placeholder="2#2#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="2#3#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[1]" disabled placeholder="2#3#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="2#4#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[1]" disabled placeholder="2#4#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="3#1#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[2]" disabled placeholder="3#1#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="3#2#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[2]" disabled placeholder="3#2#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="3#3#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[2]" disabled placeholder="3#3#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="3#4#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[2]" disabled placeholder="3#4#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="4#1#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[3]" disabled placeholder="4#1#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="4#2#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[3]" disabled placeholder="4#2#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="4#3#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[3]" disabled placeholder="4#3#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="4#4#风室压力" placement="top-start">
          <el-input v-model="formData.backward_grate_wind_pressure_PV[3]" disabled placeholder="4#4#风室压力" />
        </el-tooltip>
      </el-form-item> -->
      <!-- <el-form-item label="顺推炉排风压">
        <el-tooltip class="box-item" effect="dark" content="1#风室压力" placement="top-start">
          <el-input v-model="formData.forward_grate_wind_pressure_PV[0]" disabled placeholder="1#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="2#风室压力" placement="top-start">
          <el-input v-model="formData.forward_grate_wind_pressure_PV[1]" disabled placeholder="2#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="3#风室压力" placement="top-start">
          <el-input v-model="formData.forward_grate_wind_pressure_PV[2]" disabled placeholder="3#风室压力" />
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="4#风室压力" placement="top-start">
          <el-input v-model="formData.forward_grate_wind_pressure_PV[3]" disabled placeholder="4#风室压力" />
        </el-tooltip>
      </el-form-item> -->
    </el-form>
    <div class="m-3">
      <el-button type="primary" @click="saveCnfig">保存配置</el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "vue"
import { ElMessage } from "element-plus"
import { saveConfigApi, getInitApi } from "@/api/acc"
import { http } from "@/utils/service"

const formData = reactive({
  steam_flow_SV_range: [40, 60],
  steam_flow_PV: [0],
  air_preheater_temperature_PV: [0, 0],
  steam_header_temperature_SV_range: [0, 0],
  steam_header_temperature_PV: [0],
  incinerator_temperature_SV_range: [0, 0],
  incinerator_temperature_PV: [0, 0],
  incinerator_oxygen_content_SV_range: [0, 0],
  incinerator_oxygen_content_PV: [0],
  incinerator_pressure_SV_range: [0, 0],
  incinerator_pressure_PV: [0, 0],
  backward_grate_wind_pressure_PV: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  forward_grate_wind_pressure_PV: [0, 0, 0, 0]
})

async function saveCnfig() {
  const reqconfig = reactive<any>({
    steam_flow_SV_range_min: formData.steam_flow_SV_range[0],
    steam_flow_SV_range_max: formData.steam_flow_SV_range[1],
    steam_header_temperature_SV_range_min: formData.steam_header_temperature_SV_range[0],
    steam_header_temperature_SV_range_max: formData.steam_header_temperature_SV_range[1],
    incinerator_temperature_SV_range_min: formData.incinerator_temperature_SV_range[0],
    incinerator_temperature_SV_range_max: formData.incinerator_temperature_SV_range[1],
    incinerator_oxygen_content_SV_range_min: formData.incinerator_oxygen_content_SV_range[0],
    incinerator_oxygen_content_SV_range_max: formData.incinerator_oxygen_content_SV_range[1],
    incinerator_pressure_SV_range_min: formData.incinerator_pressure_SV_range[0],
    incinerator_pressure_SV_range_max: formData.incinerator_pressure_SV_range[1]
  })
  await saveConfigApi(reqconfig)
  ElMessage.success("保存成功!")
}

async function loadConfig() {
  const response: any = await getInitApi()
  if (response.code == 0) {
    formData.steam_flow_SV_range[0] = response.data.steam_flow_SV_range_min
    formData.steam_flow_SV_range[1] = response.data.steam_flow_SV_range_max

    formData.steam_header_temperature_SV_range[0] = response.data.steam_header_temperature_SV_range_min
    formData.steam_header_temperature_SV_range[1] = response.data.steam_header_temperature_SV_range_max

    formData.incinerator_temperature_SV_range[0] = response.data.incinerator_temperature_SV_range_min
    formData.incinerator_temperature_SV_range[1] = response.data.incinerator_temperature_SV_range_max

    formData.incinerator_oxygen_content_SV_range[0] = response.data.incinerator_oxygen_content_SV_range_min
    formData.incinerator_oxygen_content_SV_range[1] = response.data.incinerator_oxygen_content_SV_range_max

    formData.incinerator_pressure_SV_range[0] = response.data.incinerator_pressure_SV_range_min
    formData.incinerator_pressure_SV_range[1] = response.data.incinerator_pressure_SV_range_max
  }

  return response
}

async function setValsToAi() {
  await http({ url: "http://10.99.101.188:8010/ai/accs", method: "post", data: formData })
  ElMessage.success("已提交预测数据!")
}

loadConfig()
</script>

<style lang="scss">
:deep(.el-card__body) {
  padding-bottom: 2px;
}
.main-container {
  overflow-y: auto;
}
</style>
